/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "StockDayTableDialog.h"
#include "StockDayDatabase.h"

namespace QSThink
{
	StockDayTableDialog::StockDayTableDialog(QWidget *parent)
		: QDialog(parent),_ui(new Ui::StockDayViewUI)
	{
		_ui->setupUi(this);

		
	}

	StockDayTableDialog::~StockDayTableDialog()
	{
		delete _ui;
	}

	void StockDayTableDialog::load( QString symbol )
	{
		_symbol=symbol;

		StockDayFile* f= StockDayDatabase::getSingleton().getStockDayFile(symbol);
		if(!f){
			return;
		}

		int cnt=f->itemCount();
		_ui->tableWidget->setRowCount(cnt);
		for (int i=0;i<cnt;++i)
		{
			StockDayFileItem* item=f->item(i);

			float open=(float)item->open/100.0f;
			float high=(float)item->high/100.0f;
			float low=(float)item->low/100.0f;
			float close=(float)item->close/100.0f;

			QTableWidgetItem* item0=new QTableWidgetItem(QString::number(item->date));
			QTableWidgetItem* item1=new QTableWidgetItem(QString::number(open));
			QTableWidgetItem* item2=new QTableWidgetItem(QString::number(high));
			QTableWidgetItem* item3=new QTableWidgetItem(QString::number(low));
			QTableWidgetItem* item4=new QTableWidgetItem(QString::number(close));
			QTableWidgetItem* item5=new QTableWidgetItem(QString::number(item->amount,'g',16));
			QTableWidgetItem* item6=new QTableWidgetItem(QString::number(item->vol));


			_ui->tableWidget->setItem(i,0,item0);
			_ui->tableWidget->setItem(i,1,item1);
			_ui->tableWidget->setItem(i,2,item2);
			_ui->tableWidget->setItem(i,3,item3);
			_ui->tableWidget->setItem(i,4,item4);
			_ui->tableWidget->setItem(i,5,item5);
			_ui->tableWidget->setItem(i,6,item6);

		}

		

	}

	
}
